package com.wlb365.financing.modules.trade.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlb365.financing.common.constants.ApiConstants;
import com.wlb365.financing.common.constants.SysConstant;
import com.wlb365.financing.common.dto.R;
import com.wlb365.financing.common.exception.AdminException;
import com.wlb365.financing.common.utils.JsonSchemaUtil;
import com.wlb365.financing.common.utils.ShiroUtil;
import com.wlb365.financing.common.utils.StringUtils;
import com.wlb365.financing.modules.esign.service.ESignService;
import com.wlb365.financing.modules.schedule.utils.DateUtil;
import com.wlb365.financing.modules.sys.entity.Dept;
import com.wlb365.financing.modules.sys.service.IDeptService;
import com.wlb365.financing.modules.sys.service.IDictService;
import com.wlb365.financing.modules.sys.service.IUserService;
import com.wlb365.financing.modules.trade.response.QueryBankListRes;
import com.wlb365.financing.modules.trade.response.QueryPageVoucherDTO;
import com.wlb365.financing.modules.trade.response.TradeProcessDataListResult;
import com.wlb365.financing.modules.trade.response.TradeQueryProcessDataDetailRes;
import com.wlb365.financing.modules.trade.response.VoucherDetailRes;
import com.wlb365.financing.modules.trade.response.VoucherPreviewRes;
import com.wlb365.financing.modules.trade.response.VoucherQueryRes;
import com.wlb365.financing.modules.trade.response.audit.AuditDto;
import com.wlb365.financing.modules.trade.response.audit.QueryAuditListResult;
import com.wlb365.financing.modules.trade.response.data.QuerySchemaByBtypeRes;
import com.wlb365.financing.modules.trade.response.data.QuerySchemaByIdRes;
import com.wlb365.financing.modules.trade.response.voucher.VoucherUpdateRes;
import com.wlb365.financing.modules.trade.service.IAuditService;
import com.wlb365.financing.modules.trade.service.IDataService;
import com.wlb365.financing.modules.trade.service.ITradeService;
import com.wlb365.financing.modules.trade.service.IVoucherService;
import com.wlb365.financing.modules.trade.vo.TemplateVO;
import com.wlb365.financing.modules.trade.vo.VoucherQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 凭证生成管理类.
 *
 * @author zwh
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("voucher/generate")
public class VoucherGenerateController {
    private final String acceptanceInfoType = "acceptanceInfo_1";

    private final String acceptanceInfoDataType = "acceptanceInfo";
    @Autowired
    private IVoucherService voucherService;
    @Autowired
    private ITradeService tradeService;
    @Autowired
    private IDataService dataService;
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IDictService dictService;
    @Autowired
    private IAuditService auditService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ESignService eSignService;




    //凭证生成第一步：选择凭证模板
    /**
     * 选择模板页面.
     * @param compId 核心企业机构id
     * @author zwh
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequiresPermissions("voucher:generate")
    @GetMapping(value = "/choice/templateView")
    public ModelAndView choiceTemplateView(String compId, String bankId) {
        ModelAndView mv = new ModelAndView("trade/voucher_template");
        mv.addObject("compId", compId);
        mv.addObject("bankId", (bankId!=null && !"null".equals(bankId))?bankId:"");
        return mv;
    }

    /**
    * 查询模板列表.
    * @param compId 核心企业id
    * @author zwh
    * @return com.wlb365.financing.common.dto.R
    **/
    @GetMapping(value = "/choice/getTemplate")
    public R getTemplate(String compId) {
        List<TemplateVO> res = voucherService.queryTemplateList(compId);
        return R.ok(res);
    }

    //凭证生成第二步：选择验收数据
    /**
     * 凭证生成前选择验收数据页面.
     * @param tradeId 交易数据id
     * @author zwh
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequiresPermissions("voucher:generate")
    @GetMapping(value = "/selAcceptanceInfo")
    public ModelAndView generateSelAcceptanceInfoHtml(String tradeId, String bankId,  String supplierId, String templateId) {
        ModelAndView mv = new ModelAndView("trade/voucher_acceptance");
        //交易id
        mv.addObject("tradeId", tradeId);
        mv.addObject("bankId", bankId);
        mv.addObject("templateId", templateId);

        LocalDateTime generateTime = LocalDateTime.now();
        mv.addObject("generateTime", DateUtil.dateFullTimeFormat(generateTime));
        Dept supplier = deptService.getById(supplierId);
        mv.addObject("supplierName", supplier != null ? supplier.getName() : "未知供应商");

        if (StringUtils.isNotEmpty(bankId)){
            Dept dept = deptService.getById(bankId);
            mv.addObject("bankName", dept != null ? dept.getName() : "未选择银行");
        }
        LocalDateTime endTime = generateTime.plus(1, ChronoUnit.MONTHS);
        mv.addObject("endTime", DateUtil.dateFullTimeFormat(endTime));
        return mv;
    }

    /**
    * 获取验收数据模板.
    * @param tradeId 交易id
    * @author zwh
    * @return com.wlb365.financing.common.dto.R
    **/
    @GetMapping(value = "/getAcceptanceInfoSchema")
    public R getAcceptanceInfoSchema(String tradeId) {
        try {
            TradeProcessDataListResult result = tradeService.queryProcessDataDetailList(tradeId, null, acceptanceInfoDataType);
            if (!ApiConstants.SUCCESS_CODE.equals(result.getCode())) {
                log.error("获取数据异常：" + result.getMsg() + result.getSubMsg());
                throw new AdminException("获取模板异常");
            }
            if (CollectionUtil.isEmpty(result.getItems())) {
                throw new AdminException("验收数据为空");
            }
            QuerySchemaByIdRes res = dataService.querySchemaById(result.getItems().get(0).getTemplateId());
            if (!ApiConstants.SUCCESS_CODE.equals(res.getCode())) {
                log.error("获取数据模板异常：" + res.getMsg() + res.getSubMsg());
                throw new AdminException("获取数据模板异常");
            }
            //String json = "{\"schema\":{\"type\":\"object\",\"required\":[\"ladOrder\",\"logOrder\",\"acceptanceNumber\",\"driName\",\"driCerNo\",\"carNo\",\"shippingWeight\",\"actWeight\",\"acceptanceImgPath\"],\"properties\":{\"ladOrder\":{\"title\":\"云商提单号\",\"type\":\"string\",\"maxLength\":64,\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"logOrder\":{\"title\":\"物流提单号\",\"type\":\"string\",\"maxLength\":64,\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"acceptanceNumber\":{\"title\":\"验收单号\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"aofRecognition\":{\"title\":\"验收人人脸识别\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"driName\":{\"title\":\"司机名称\",\"type\":\"string\",\"maxLength\":32,\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"driCerNo\":{\"title\":\"司机身份证号\",\"type\":\"string\",\"maxLength\":32,\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"carNo\":{\"title\":\"车辆车牌号\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"shippingWeight\":{\"title\":\"发货重量\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"actWeight\":{\"title\":\"实际验收重量\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"acceptanceList\":{\"title\":\"验收货物明细\",\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"acceptedGoodsName\",\"acceptTmofgoods\",\"smAcceptanceWeight\"],\"properties\":{\"acceptedGoodsName\":{\"title\":\"验收货物名称\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"acceptTmofgoods\":{\"title\":\"验收货物材质\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"smAcceptanceWeight\":{\"title\":\"单一材质验收重量\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}},\"resAcceptance\":{\"title\":\"工地验收参考基价\",\"type\":\"string\",\"default\":\"0\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}}},\"ui:order\":[\"acceptedGoodsName\",\"acceptTmofgoods\",\"smAcceptanceWeight\",\"resAcceptance\"]},\"uniqueItems\":false},\"acceptanceImgPath\":{\"title\":\"验收图片\",\"type\":\"string\",\"ui:options\":{\"width\":\"30%\",\"placeholder\":\"请输入\"}}},\"ui:order\":[\"ladOrder\",\"logOrder\",\"acceptanceNumber\",\"aofRecognition\",\"driName\",\"driCerNo\",\"carNo\",\"shippingWeight\",\"actWeight\",\"acceptanceList\",\"acceptanceImgPath\"]},\"uiSchema\":{},\"formFooter\":{\"show\":false},\"formProps\":{\"inline\":true,\"inlineFooter\":true,\"layoutColumn\":3,\"labelWidth\":\"100px\",\"labelSuffix\":\"：\"}}";
            Map<String,Object> schema = JsonSchemaUtil.execute(res.getTemplateData());
            return R.ok(schema);
        } catch (Exception e){
            e.printStackTrace();
            throw new AdminException("获取验收数据异常");
        }
    }

    /**
     * 获取验收数据.
     * @param tradeId 交易id
     * @author zwh
     * @return com.wlb365.financing.common.dto.R
     **/
    @GetMapping(value = "/getAcceptanceInfo")
    public R getAcceptanceInfoList(String tradeId, String templateId) {
//        String json = "{\"items\":[{\"processId\":\"080b9e01baf546fcbced619de0555673\",\"stepNum\":1,\"dataType\":\"acceptanceInfo_1\",\"selected\":true,\"templateId\":\"2000000000000003001\",\"metadata\":\"\",\"data\":\"{\\\"ladOrder\\\":\\\"11\\\",\\\"logOrder\\\":\\\"1111\\\",\\\"acceptanceNumber\\\":\\\"111\\\",\\\"aofRecognition\\\":\\\"111\\\",\\\"driName\\\":\\\"赵六\\\",\\\"driCerNo\\\":\\\"41042110010101011\\\",\\\"carNo\\\":\\\"京A201921\\\",\\\"shippingWeight\\\":\\\"20\\\",\\\"actWeight\\\":\\\"12\\\",\\\"acceptanceList\\\":[{\\\"acceptedGoodsName\\\":\\\"钢筋水泥\\\",\\\"acceptTmofgoods\\\":\\\"好材质\\\",\\\"smAcceptanceWeight\\\":\\\"12\\\",\\\"resAcceptance\\\":\\\"12\\\"}],\\\"acceptanceImgPath\\\":[\\\"http://n.sinaimg.cn/mil/8_img/upload/93f8054c/600/w1920h1080/20210517/44ca-kpzzqna9255588.jpg\\\",\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/700/w900h600/20190604/e7d5-hxyuaph1376688.jpg\\\"]}\",\"uiSchema\":\"{\\\"acceptanceImgPath\\\":{\\\"ui:src\\\":\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/732/w930h602/20210517/8ec4-kqhwhri5903885.jpg\\\",\\\"ui:options\\\":{\\\"style\\\":{\\\"width\\\":\\\"100px\\\",\\\"height\\\":\\\"100px\\\"}},\\\"ui:widget\\\":\\\"el-image\\\",\\\"ui:preview-src-list\\\":[\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/732/w930h602/20210517/8ec4-kqhwhri5903885.jpg\\\",\\\"http://n.sinaimg.cn/news/1_img/upload/853df563/783/w950h633/20210126/05bb-kicwvzq5377892.jpg\\\",\\\"http://n.sinaimg.cn/news/1_img/upload/853df563/783/w633h950/20210119/0f87-khxeamv4227475.jpg\\\"]}}\",\"createDate\":\"2021-05-13 15:16:17\",\"updateDate\":\"2021-05-13 15:16:19\"},{\"processId\":\"080b9e01baf546fcbced619de0555673\",\"stepNum\":2,\"dataType\":\"acceptanceInfo_1\",\"selected\":true,\"templateId\":\"2000000000000003001\",\"metadata\":\"\",\"data\":\"{\\\"ladOrder\\\":\\\"22\\\",\\\"logOrder\\\":\\\"22222\\\",\\\"acceptanceNumber\\\":\\\"111\\\",\\\"aofRecognition\\\":\\\"111\\\",\\\"driName\\\":\\\"赵六1\\\",\\\"driCerNo\\\":\\\"41042110010101011\\\",\\\"carNo\\\":\\\"京A201922\\\",\\\"shippingWeight\\\":\\\"20\\\",\\\"actWeight\\\":\\\"12\\\",\\\"acceptanceList\\\":[{\\\"acceptedGoodsName\\\":\\\"钢筋水1泥\\\",\\\"acceptTmofgoods\\\":\\\"好材质\\\",\\\"smAcceptanceWeight\\\":\\\"12\\\",\\\"resAcceptance\\\":\\\"12\\\"}],\\\"acceptanceImgPath\\\":[\\\"http://n.sinaimg.cn/mil/8_img/upload/93f8054c/600/w1920h1080/20210517/44ca-kpzzqna9255588.jpg\\\",\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/700/w900h600/20190604/e7d5-hxyuaph1376688.jpg\\\"]}\",\"uiSchema\":\"{\\\"acceptanceImgPath\\\":{\\\"ui:src\\\":\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/732/w930h602/20210517/8ec4-kqhwhri5903885.jpg\\\",\\\"ui:options\\\":{\\\"style\\\":{\\\"width\\\":\\\"100px\\\",\\\"height\\\":\\\"100px\\\"}},\\\"ui:widget\\\":\\\"el-image\\\",\\\"ui:preview-src-list\\\":[\\\"http://n.sinaimg.cn/default/1_img/upload/3933d981/732/w930h602/20210517/8ec4-kqhwhri5903885.jpg\\\",\\\"http://n.sinaimg.cn/news/1_img/upload/853df563/783/w950h633/20210126/05bb-kicwvzq5377892.jpg\\\",\\\"http://n.sinaimg.cn/news/1_img/upload/853df563/783/w633h950/20210119/0f87-khxeamv4227475.jpg\\\"]}}\",\"createDate\":\"2021-05-13 15:16:17\",\"updateDate\":\"2021-05-13 15:16:19\"}]}";
//        TradeProcessDataListResult result = JSONObject.parseObject(json, TradeProcessDataListResult.class);
        //查询阶段数据列表
        TradeProcessDataListResult result = tradeService.queryProcessDataDetailList(tradeId, templateId, acceptanceInfoDataType);
        List<Map<String, Object>> data = new ArrayList<>();
        for (TradeQueryProcessDataDetailRes item : result.getItems()) {
            Map<String, Object> sub = JSONObject.parseObject(item.getData(), Map.class);
            sub.put("id", item.getProcessId() + ":" + item.getStepNum());//组装主键
            sub.put("createDate", item.getCreateDate());
            sub.put("updateDate", item.getUpdateDate());
            sub.put("selected", item.getSelected());//是否可选中标识true可选择，false不可选
            data.add(sub);
        }
        Page<Map<String, Object>> page = new Page<>();
        page.setCurrent(1);
        page.setSize(data.size());
        page.setTotal(data.size());
        page.setRecords(data);
        return R.ok(page);
    }

    //凭证生成第三步：凭证预览

    /**
     * 凭证预览页面.
     * @param tradeId 交易数据id
     * @param bankId 银行id
     * @param ids 选择数据id列表
     * @author zwh
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequiresPermissions("voucher:generate")
    @GetMapping(value = "/preview")
    public ModelAndView generatePreviewHtml(String tradeId, String bankId, String ids, String templateId) {
        ModelAndView mv = new ModelAndView("trade/voucher_preview.html");
        //交易id
        mv.addObject("tradeId", tradeId);
//        QuerySchemaByBtypeRes res = dataService.querySchema("voucherInfo", bankId);
        mv.addObject("bankId", bankId);
        mv.addObject("templateId", templateId);
        mv.addObject("ids", ids);
        return mv;
    }

    /**
     * 获取凭证预览信息.
     *
     * <p>用于凭证生成前的数据预览</p>
     * @param tradeId 交易数据id
     * @param templateId 模板id
     * @param ids 验收数据id（processId:stepNum），多个以英文逗号分隔
     * @author zwh
     * @return com.wlb365.financing.common.dto.R
     **/
    @RequiresPermissions("voucher:generate")
    @GetMapping(value = "/preview/info")
    public R generatePreview(String tradeId, String templateId, String bankId, String ids) {
        VoucherPreviewRes res = voucherService.voucherPreview(tradeId, templateId, ids);
        Map<String, Object> map = new HashMap<>();
        map.put("contractNo", res.getContractNo());
        map.put("generateTime", res.getGenerateTime());
        map.put("supplierName", res.getSupplierName());
        if (StringUtils.isNotEmpty(bankId)){
            Dept dept = deptService.getById(bankId);
            map.put("bankName", dept != null ? dept.getName() : "未选择银行");
        }
        map.put("endTime", res.getEndTime());
        map.put("templateData", JSONUtil.parseObj(res.getTemplateData(), true, true));
        //map.put("voucherData", JSONUtil.parseObj("{\"contractInfo\":{\"proOrder\":\"10000\",\"entryName\":\"民生银行\",\"refNumber\":\"20000\",\"bidWinningNoticeNumber\":\"200001\",\"bidWinningNoticeRoute\":\"/home/ap/nas/\",\"traAmount\":\"800000.00\",\"traSigningTime\":\"2021-04-1212:00:00\",\"buyerId\":\"111111\",\"buyerName\":\"张三\",\"comPlayAccount\":\"play1573676\",\"sellerId\":\"999999\",\"sellerName\":\"李四\",\"comMakeAccount\":\"lisi123456\",\"projectList\":[{\"projectInfo\":{\"markNumber\":\"123\",\"markName\":\"案例名称\",\"material\":\"材质名称\",\"specificationModel\":\"规格型号\",\"meteringUnit\":\"吨\",\"quantity\":\"10\"}}],\"contractList\":[{\"contractObject\":{\"url\":[\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.tupkaeksunset.com%2Ffiles%2F5314%2F2105%2F5040%2FIMG_3660.jpg&refer=http%3A%2F%2Fwww.tupkaeksunset.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1620894591&t=6352af0839663aa82d7b9ddc71ef72fa\",\"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3228549874,2173006364&fm=26&gp=0.jpg\"]}}]},\"supplyInfo\":{\"list\":[{\"yunOrder\":\"10009281\",\"orderExecutionList\":[{\"logOrder\":\"12312312\",\"relId\":\"414\",\"relName\":\"兰格\",\"logUniPrice\":\"11212\",\"model\":\"0\",\"lodAddress\":\"北京市丰台区六里桥北\",\"unlAddress\":\"北京市大兴区西红门\",\"gooName\":\"钢筋水泥\",\"lodWeight\":\"20\",\"actWeight\":\"11\",\"driName\":\"王五\",\"driCerNo\":\"41042101010101011\",\"carNo\":\"京K21231\",\"recTime\":\"2021-04-1312:00:00\"}]},{\"yunOrder\":\"10009282\",\"orderExecutionList\":[{\"logOrder\":\"12312312\",\"relId\":\"4124\",\"relName\":\"兰格1\",\"logUniPrice\":\"112112\",\"model\":\"0\",\"lodAddress\":\"北京市1丰台区六里桥北\",\"unlAddress\":\"北京市大兴区西红门\",\"gooName\":\"钢筋水1泥\",\"lodWeight\":\"20\",\"actWeight\":\"11\",\"driName\":\"王五\",\"driCerNo\":\"41042101010101011\",\"carNo\":\"京K21231\",\"recTime\":\"2021-04-1312:00:00\"},{\"logOrder\":\"1231122312\",\"relId\":\"42124\",\"relName\":\"兰格2\",\"logUniPrice\":\"112112\",\"model\":\"0\",\"lodAddress\":\"北京市2丰台区六里桥北\",\"unlAddress\":\"北京市2大兴区西红门\",\"gooName\":\"钢筋水2泥\",\"lodWeight\":\"20\",\"actWeight\":\"11\",\"driName\":\"王五2\",\"driCerNo\":\"41042101010101011\",\"carNo\":\"京K221231\",\"recTime\":\"2021-04-1312:00:00\"}]}]},\"acceptanceInfo\":{\"acceptanceDetails\":{\"ladOrder\":\"11\",\"logOrder\":\"1111\",\"acceptanceNumber\":\"111\",\"aofRecognition\":\"111\",\"driName\":\"赵六\",\"driCerNo\":\"41042110010101011\",\"carNo\":\"京A201921\",\"shippingWeight\":\"20\",\"actWeight\":\"12\",\"acceptanceList\":[{\"acceptedGoodsName\":\"钢筋水泥\",\"acceptTmofgoods\":\"好材质\",\"smAcceptanceWeight\":\"12\",\"resAcceptance\":\"12\"}],\"acceptanceVideoList\":[{\"acceptanceImgPath\":[\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.tupkaeksunset.com%2Ffiles%2F5314%2F2105%2F5040%2FIMG_3660.jpg&refer=http%3A%2F%2Fwww.tupkaeksunset.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1620894591&t=6352af0839663aa82d7b9ddc71ef72fa\",\"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3228549874,2173006364&fm=26&gp=0.jpg\"]}]},\"proOrder\":\"10000\",\"entryName\":\"民生银行\",\"refNumber\":\"20000\"},\"settlementInfo\":{\"statementNumber\":\"12344420000\",\"statementAmount\":\"200\",\"statementList\":[{\"acceptanceNumber\":\"12345654\",\"acceptanceCargoWeight\":\"4100\",\"acceptedGoodsAmount\":\"10000\"},{\"acceptanceNumber\":\"234564654\",\"acceptanceCargoWeight\":\"51100\",\"acceptedGoodsAmount\":\"25454\"}],\"proOrder\":\"10000\",\"entryName\":\"民生银行\",\"refNumber\":\"20000\"}}", true, true));
        map.put("voucherData", JSONUtil.parseObj(res.getVoucherData(), true, true));

        map.put("uiSchema", JSONUtil.parseObj(res.getUiSchema(), true, true));
        return R.ok(map);
    }

    //凭证生成第四步：凭证生成
    /**
     * 凭证生成.
     * @param tradeId 交易数据id
     * @param templateId 模板id
     * @param bankId 银行id
     * @param ids 数据id
     * @author zwh
     * @return com.wlb365.financing.common.dto.R
     **/
    @RequiresPermissions("voucher:generate")
    @PostMapping(value = "/create")
    public R generate(String tradeId, String templateId, String bankId, String ids) {
        return R.ok(voucherService.generate(tradeId, templateId, bankId, ids));
    }

}
